<?php
/**
 * Created by PhpStorm.
 * User: andy
 * Date: 2019/8/29
 * Time: 下午2:22
 */

namespace app\control\controller;


use app\common\model\AdminMenuModel;
use app\common\model\AdminUserModel;
use think\App;
use think\Controller;
use think\facade\Request;
use think\facade\Session;

class AdminBaseController extends Controller
{
    protected $middleware = ['CheckAdminLogin','AdminAuth'];

    protected $uid; //管理员ID
    protected $userInfo; //管理员信息

    /**
     * 构造方法
     * AdminBaseController constructor.
     * @param Request $request
     * @param App|null $app
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function __construct(Request $request,App $app = null)
    {
        if (!session_id()) Session::start();
        parent::__construct($app);

        $arr=[
            'app'=>Request::module(),
            'controller'=>Request::controller(),
            'action'=>Request::action(),
        ];

        $this->uid = Session::get('UID');
        $user=AdminUserModel::get($this->uid);

        $this->userInfo=$user;
        $this->assign('userInfo',$user);

        //面包屑
        $this->getBread($arr);
    }

    /**
     * 获取面包屑
     * @param $req
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    private function getBread($req){
        $am=new AdminMenuModel();
        $m=$am->menuBread($req);
        $this->assign("menuBread",$m);
    }

}